//
//  ZyUIButton.swift
//  SwiftLearnAll
//
//  Created by iosdev1 on 2017/6/28.
//  Copyright © 2017年 ygsoft. All rights reserved.
//

import UIKit

class ZyUIButton: UIButton {

    class func shared(title:String, font:CGFloat, color:UIColor, bgcolor:UIColor, radius:CGFloat, btnClosure:@escaping (_ btn:UIButton) -> Void) -> UIButton {
        let btn = self.btnInitWithEvent(title: title, font: font, color: color, bgcolor: bgcolor, radius: radius, btnClosure: btnClosure)
        return btn
    }

    //    自定义button
    class func btnInitWithEvent(title:String, font:CGFloat, color:UIColor, bgcolor:UIColor, radius:CGFloat, btnClosure:@escaping (_ btn:UIButton) -> Void) -> UIButton {
        let btn:UIButton = UIButton.init()
        btn.setTitle(title, for: UIControlState.normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: font)
        btn.setTitleColor(color, for: UIControlState.normal)
        btn.backgroundColor = bgcolor
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = radius
        btn.addTarget(self, action: #selector(btnInitMyClick(btn:buttonClosure:)), for: UIControlEvents.touchUpInside)
        return btn
    }

    //    实现button点击效果 只能是类方法
    class func btnInitMyClick(btn:UIButton, buttonClosure:(_ button:UIButton) -> Void) -> Void {
        echo(data: "\(String(describing: btn.currentTitle))")
        buttonClosure(btn)
    }

}
